package com.chhuang.core.model;

import java.io.Serializable;

import javax.xml.bind.annotation.XmlTransient;

import com.sun.xml.bind.CycleRecoverable.Context;

/**
 * Default implementation for interface <code>Persistable</code>
 *
 * @author JackDou
 * @version 2012-4-12
 */
public abstract class AbstractPersistentModel implements Persistable {
    /**
	 * serialVersionUID setting
	 */
	private static final long serialVersionUID = -7860189808902387772L;

	/**
     * @return the persistence identity of this instance
     *
     * @see com.edoc.reference.jl.framework.dao.model.Persistable#getId()
     */
	@XmlTransient
    public abstract Serializable getId();

    /* (non - Javadoc)
     * <p>Title: setId</p>
     * <p>Description: </p>
     * @param id
     * @see com.synergyinfo.efs.model.Persistable#setId(java.io.Serializable)
     */ 
     public abstract void setId(Serializable id);
    /**
     * @param object
     *            an instance of <code>Persistable</code>
     * @return <code>true</code> if <code>object</code> equals this;
     *         otherwise return <code>false</code>.
     *
     * @see java.lang.Object#equals(java.lang.Object)
     */
    public boolean equals(Object object) {
        if (this == object) {
            return true;
        }
        if (!(object instanceof Persistable)) {
            return false;
        }
        final Persistable perisisable = (Persistable) object;
        if (!this.getId().equals(perisisable.getId())) {
            return false;
        }
        return true;
    }

    /**
     * @return an unique hash code for each instance of the class
     */
    public int hashCode() {
        return super.hashCode() * 18 + 1977;
    }

    /**
     * @return a <code>String</code> consists of all properties
     * @see java.lang.Object#toString()
     */
    public abstract String toString();
    
    /** 
     * @param arg0
     * @return
     */
    public abstract Object onCycleDetected(Context arg0);
}
